//
//  SearchTableViewCell.m
//  JunZeWristband
//
//  Created by Kendama on 2017/8/26.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "SearchTableViewCell.h"
NSString *const kSearchTableViewCellIdentifier = @"kSearchTableViewCellIdentifier";

@implementation SearchTableViewCell

+ (instancetype)dequeueReusableWithTableView:(UITableView *)tableView
{
    SearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kSearchTableViewCellIdentifier];
    if (cell == nil)
    {
        cell = [[SearchTableViewCell alloc]init];
    }
    return cell;
}

- (instancetype)init
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kSearchTableViewCellIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self masLayoutSubview];
    }
    return self;
}



- (void)didClickBindButton
{
//    self.bindButton.selected = !self.bindButton.selected;
    if (self.bindDeviceBlcok) {
        self.bindDeviceBlcok();
    }
}

- (UILabel *)nameLabel
{
    if(!_nameLabel)
    {
        UIView *superView = self.contentView;
        _nameLabel = [[UILabel alloc]init];
        [superView addSubview:_nameLabel];
        [_nameLabel setFont:[UIFont systemFontOfSize:15]];
        [_nameLabel setTextColor:[UIColor darkGrayColor]];
    }
    return _nameLabel;
}

- (UIButton *)bindButton
{
    if(!_bindButton)
    {
        UIView *superView = self.contentView;
        _bindButton = [[UIButton alloc]init];
        [superView addSubview:_bindButton];
        [_bindButton setTitle:MyNSLocalizedString(@"解绑") forState:UIControlStateNormal];
        [_bindButton setTitle:MyNSLocalizedString(@"绑定") forState:UIControlStateSelected];
        [_bindButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [_bindButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_bindButton setBackgroundImage:[UIImage imageNamed:@"bind"] forState:UIControlStateNormal];
        [_bindButton setBackgroundImage:[UIImage imageNamed:@"unbind"] forState:UIControlStateSelected];
        [_bindButton addTarget:self action:@selector(didClickBindButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _bindButton;
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self.contentView;
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(54));
        make.right.mas_equalTo(self.bindButton.mas_left);
    }];
    
    [self.bindButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.right.mas_equalTo(superView.mas_right).with.offset(px1080Width(-54));
    }];
}

@end
